﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using LevenBlog.Core.Entities;

namespace LevenBlog.Core.Install.Operations {
    public class SqliteConfigUpdateInstall : IInstallOperation {
        #region IInstallOperation Members

        public string Name {
            get { return CoreResource.install_sqliteconfigupdate_name; }
        }

        public string Intro {
            get { return CoreResource.install_sqlitedatatablecreate_intro; }
        }

        public object Data {
            get;
            set;
        }

        public OperationResult Execute(OperationContext context) {
            List<string> errors = new List<string>();
            try {
                if (!(Data is lb_config)) {
                    errors.Add(CoreResource.install_sqliteconfigupdate_dataerror);
                }
                lb_config config = Data as lb_config;
                context.DbFactory.Config.Update(context.DbProvider, config);
            } catch (Exception e) {
                errors.Add(e.Message);
            }
            return new OperationResult(errors.Count > 0 ? false : true, errors);
        }

        #endregion
    }
}
